package news.paper.tintuc.tinnong.docbao.doctin.fragment;

import news.paper.tintuc.tinnong.docbao.doctin.Activity_Menu;
import news.paper.tintuc.tinnong.docbao.doctin.adapter.MenuAdapter;
import news.paper.tintuc.tinnong.docbao.doctin.util.Constrant;
import news.paper.tintuc.tinnong.docbao.doctin.views.SampleItem;
import news.paper.tintuc.tinnong.docbao.doctin.R;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

@SuppressLint("ValidFragment")
public class MenuFragment extends ListFragment {


	public MenuFragment() {
		super();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.test_menu_list, null);
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		Constrant.adapter = new MenuAdapter(getActivity());
//		for (int i = 0; i < menuText.length; i++) {
//			Constrant.adapter.add(new SampleItem(menuIcon[i], menuText[i]));
//		}
		if(Constrant.arrayListNews != null)
		for (int i = 0; i < Constrant.arrayListNews.size(); i++) {
			Constrant.adapter.add(new SampleItem(Constrant.arrayListNews.get(i).getListName()));
		}
		setListAdapter(Constrant.adapter);
	}

	@Override
	public void onListItemClick(ListView lv, View v, int position, long id) {
		Constrant.selectedPosition = position;
		Constrant.adapter.notifyDataSetInvalidated();

		if (getActivity() == null)
			return;
		else {
			Activity_Menu tsm = (Activity_Menu) getActivity();
			tsm.switchContent(position);
		}
	}

	// private class SampleItem {
	// public int menuImg;
	// public String menuText;
	//
	// public SampleItem(int menuImg, String menuText) {
	// this.menuImg = menuImg;
	// this.menuText = menuText;
	// }
	// }

	// private class MenuAdapter extends ArrayAdapter<SampleItem> {
	// public MenuAdapter(Context context) {
	// super(context, 0);
	// }
	//
	// public View getView(int position, View contentView, ViewGroup parentView)
	// {
	// if (contentView == null) {
	// contentView = LayoutInflater.from(getContext()).inflate(
	// R.layout.menu_item, null);
	// }
	// TextView textView = (TextView) contentView
	// .findViewById(R.id.menu_item_textview);
	// TextView text = (TextView) contentView
	// .findViewById(R.id.menu_item_text);
	// text.setText(getItem(position).menuText);
	// ImageView icon = (ImageView) contentView
	// .findViewById(R.id.menu_item_icon);
	// icon.setImageResource(getItem(position).menuImg);
	//
	// if (Constrant.selectedPosition == position) {
	// contentView.setBackgroundColor(getResources().getColor(
	// R.color.sm_menulist_selected_bg));
	// icon.setSelected(true);
	// text.setTextColor(Color.parseColor("#f6f6f6"));
	// textView.setBackgroundColor(Color.parseColor("#00b0ff"));
	// } else {
	// contentView.setBackgroundColor(getResources().getColor(
	// R.color.sm_menulist_unselect_bg));
	// icon.setSelected(false);
	// text.setTextColor(Color.parseColor("#aaaaaa"));
	// textView.setBackgroundResource(R.drawable.null2);
	// }
	// return contentView;
	// }
	// }

}